﻿package divinity.utils
{
	import flash.display.DisplayObject;
	import flash.utils.getDefinitionByName;

	public class Filters
	{
		static private var clipFilters:Array;
		static private var filtersToApply:Array;
		public function Filters()
		{
			


		}
		public static function addFilters(clip:DisplayObject=null,filts:String=null):void
		{

			if (clip!=null)
			{
				clipFilters=[];
				filtersToApply=[];

				clipFilters=filts.split("|");
				if (filts!=""&&filts!=null)
				{
					for (var n=0; n<clipFilters.length; n++)
					{
						filtersToApply[n]=makeFilter(n);
					}
					clip.filters=filtersToApply;
				}
			}
		}
		private static function makeFilter(num:int):*
		{
			var filt:Array=clipFilters[num].split(",");
			var filtName:Class=getDefinitionByName("flash.filters."+filt[0]) as Class;
			var filter:*=new filtName();

			for (var p=1; p<filt.length; p++)
			{
				var par:*=filt[p].split(":");
				filter[par[0]]=par[1];
			}
			return filter;
		}		
	}
}